﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Collections.Generic;
using System.Text;

using Rison.Web.Common;

namespace Rison.Web.CommonPage
{
    /// <summary>
    /// 描述：文档连接的标签控件
    /// 功能：显示文档连接
    /// 作者：sfz
    /// 日期：2008-7-23
    /// </summary>
    public partial class FilesLabel : UserControl 
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected string UrlBase
        {
            get { return PageGlobalParams.PageUrlBase2; }
        }

        //只绑定一个文档
        public void BindLabel(string path, string name)
        {
            if (path == null || name == null)
                throw new ArgumentNullException("path or name");

            if (path == string.Empty || name == string.Empty)
                return;

            //生成文档链接
            StringBuilder builder = new StringBuilder(300);

            //显示上传文档内容
            builder.Append("<table cellSpacing=\'0\' cellPadding=\'2\' border=\'0\'>");
            builder.Append("<tr><td width=\'20px\'><IMG height=\'12\' src=\'");
            builder.Append(UrlBase);
            builder.Append("/CommonPage/FileUploader/images/i.p.attachfile.gif\' width=\'15\'></td>");
            builder.Append("<td align=left><a href=\'");
            builder.Append(UrlBase);
            builder.Append(path);
            builder.Append("\' TARGET=\'_blank\'>");
            builder.Append(name);
            builder.Append("</a></td></tr>");
            builder.Append("</table>");
            this.labFiles.Text = builder.ToString();
        }

        //绑定多个文档
        public void BindLabel(List<string> paths, List<string> names)
        {
            if (paths == null || names == null )
                throw new ArgumentNullException("paths or names");
            if (paths.Count != names.Count)
                throw new ArgumentException("输入的参数不正确，参数名：paths，names");
            if (paths.Count == 0)
                return;

            //生成文档链接
            StringBuilder builder = new StringBuilder(300);

            //显示上传文档内容
            builder.Append("<table cellSpacing=\'0\' cellPadding=\'2\' border=\'0\'>");
            for (int i = 0; i < paths.Count;i++ )
            {
                builder.Append("<tr><td width=\'20px\'><IMG height=\'12\' src=\'");
                builder.Append(UrlBase);
                builder.Append("/CommonPage/FileUploader/images/i.p.attachfile.gif\' width=\'15\'></td>");
                builder.Append("<td align=left><a href=\'");
                builder.Append(UrlBase);
                builder.Append(paths[i]);
                builder.Append("\' TARGET=\'_blank\'>");
                builder.Append(names[i]);
                builder.Append("</a></td></tr>");
            }
            builder.Append("</table>");
            this.labFiles.Text = builder.ToString();
        }

        //Label的文本属性
        public string Text
        {
            get
            {
                return this.labFiles.Text;
            }
            set
            {
                this.labFiles.Text = value;
            }

        }
    }
}